<?php
/*
	[gunianwang system]
	NAME:img_comment_control 图片评论管理系统
	AUTHOR:sql
	DATE:2012-07-13
*/

if (!defined('IN_ELS'))
{
    die('Hacking attempt');
}
class control extends img_commentbase {
	var $pagecount 		= 0;
	var $currendnum 	= 1;
	var $pageSize 		= 50;	//每页多少条
	var $pageNumSize 	= 10;	//分页数
	
	function control() {
		$this->img_commentbase();
		if(!empty($_REQUEST['currendnum'])){
			$this->currendnum=$_REQUEST['currendnum'];
		}
		$act=empty($_REQUEST['a']) ? 'empty' : $_REQUEST['a'];
		
		if($act=="empty")				$this->img_commentList();//评论图片列表
		if($act=="commentdel")			$this->commentdel();//删除单条评论
		if($act=="commentdelall")			$this->commentdelAll();//删除批量评论
		if($act=="up_is_ok")			$this->up_is_ok();//修改评论有效性
		
		
		
	}  
	function img_commentList()                //主页显示
	{
		// news List
		$where = "where 1=1 ";
		$url = "";

		$dataCount=$this->getCommentCount($where);
		$startNum = $this->pageSize*($this->currendnum-1);
		$limitText = " limit ".$startNum." , ".$this->pageSize;
		$pagecountdata=array();
		require_once ELS_ROOT.'lib/paging.class.php';
		$pg =  new paging();
		$pg -> setLinkText("<a href='admin.php?p=img_comment$url&currendnum=!!PageNum!!'>!!LinkText!!</a>");
		$pg -> setCurrendnum(  $this-> currendnum);
		$pg -> setPageSize(    $this-> pageSize);
		$pg -> setPageNumSize( $this-> pageNumSize);
		$pg -> setDataCount(   $dataCount);
		$pagecountdata = $pg ->makePageText();
		
		$list=$this->getImgCommentList($where,$limitText);
		foreach($list as $k=>$v)
		{
			$sql_user_name = $this->db->result_first("select user_name from gnw_user where id=".$v['m_id']." limit 1");
			$list[$k]['user_name'] = $sql_user_name;

			$sql_img_content = $this->db->result_first("select content from gnw_u_image where id=".$v['img_id']." limit 1");
			$list[$k]['img_content'] = $sql_img_content;
		}

		$this->view->assign('list',$list);
		$this->view->assign('pagecount' ,$pagecountdata);
		$this->view->assign('currendnum',$currendnum);
		$this->view->assign('user_leve',$search_1);
		$this->view->display('img_comment_list');

	}





	// 删除单个mail站内信
	function commentdel(){
		$comment_id = empty($_REQUEST['comment_id'])?"":$_REQUEST['comment_id'];
		if($comment_id!='')
		{
			$this->db->query("DELETE FROM gnw_img_comment WHERE id = '$comment_id' limit 1");
			echo "<script>alert('删除成功！');</script>";
			$this->pageRedirect("?p=img_comment");
		}
		
	}
	function commentdelAll()
	{
		$comment_id= empty($_POST['ids'])?array():$_POST['ids'];
		//print_r($mail_id);exit;
		//删除
		if($comment_id){
			for($i=0;$i<count($comment_id);$i++){
				
				$this->db->query("DELETE FROM gnw_img_comment WHERE id = '$comment_id[$i]'");
			}
			echo "<script>alert('批量删除成功！');</script>";
		}
		
		$this->pageRedirect("?p=img_comment");
	}

	function up_is_ok()
	{
		$id = $_REQUEST['id'];
		$where = " id=$id ";
		$sql="select is_ok from gnw_img_comment where id=$id limit 1";
		$is_ok =$this->db->result_first($sql);
		
		if($is_ok==1 && $id!='')
		{
			$data_arr['is_ok']=2;
		}
		else if($is_ok==2 && $id!='')
		{
			$data_arr['is_ok']=1;
		}
		$this->updateimgcomment($data_arr,$where);
		echo $data_arr['is_ok'];
	}

	


}
?>